package ug.co.icom.kyazze.healthticket.mongoHQ;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.util.Log;

public class MySqlPostPublicKey extends AsyncTask<String, String, String> {

	JSONParser jsonParser = new JSONParser();
	private static String post_main_table = "http://appitconsult.com/healthticket/h_scripts/create_main_details.php";
	private static final String TAG_SUCCESS = "success";
	private static String TAG_VALUE = "false";

	@Override
	protected String doInBackground(String... args) {
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		params.add(new BasicNameValuePair("phone_number", args[0]));
		params.add(new BasicNameValuePair("public_key", args[1]));
		params.add(new BasicNameValuePair("master_key_url", args[2]));

		JSONObject json = jsonParser.makeHttpRequest(post_main_table, "POST",
				params);

		// check log cat fro response
		Log.d("Create Response", json.toString());

		// check for success tag
		try {
			int success = json.getInt(TAG_SUCCESS);

			if (success == 1) {
				// successfully created product
				TAG_VALUE = "true";
			} else {
				// failed to create product
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return TAG_VALUE;
	}

	@Override
	protected void onPostExecute(String result) {
		// TODO Auto-generated method stub
		super.onPostExecute(result);
	}

}
